//
// Created by 朕与将军解战袍 on 2022/3/12.
//

#ifndef TRUETYPERENDER_RASTER_H
#define TRUETYPERENDER_RASTER_H

#include "glyph.h"
#include "ttf_setup.h"

#define BLACK 0
#define WHITE 255

#define EMPTY BLACK
#define FILLED WHITE

typedef struct DiagonalLine {
    Vertex topLeft;
    Vertex downRight;
} DiagonalLine;


TTFStatus seedFillGlyph(
        OUT unsigned char *bitmap,
        IN int w,
        IN int h,
        IN Glyph *glyph,
        IN int size);

/**
 * 生成界限
 * @param bitmap bmp
 * @param w width of bmp
 * @param h height of bmp
 * @param glyph
 * @param size glyph size
 * @error
 */
TTFStatus generateBoundary(
        OUT DiagonalLine* diagonalLine,
        OUT unsigned char *bitmap,
        IN int w,
        IN int h,
        IN Glyph *glyph,
        IN int size);

TTFStatus generateBezierQuadraticBoundary(
        OUT DiagonalLine* diagonalLine,
        OUT unsigned char *bitmap,
        IN int w,
        IN int h,
        IN BezierQuadratic* curve,
        IN int size);

/**
 * 用于寻找种子像素
 * @param seed 种子像素
 * @param diagonalLine 封闭图形的"对角线"
 * @param bitmap 已经生成了封闭轮廓的 bitmap
 * @param w width of bitmap
 * @error CAN_NOT_FOUND_SEED(0xff) 找不到种子像素
 */
TTFStatus searchSeed(
        OUT Vertex *seed,
        IN DiagonalLine *diagonalLine,
        IN const unsigned char* bitmap,
        IN int w);
#define CAN_NOT_FOUND_SEED ((TTFStatus) 0xff)

#endif //TRUETYPERENDER_RASTER_H
